package com.dream.flutter_app_demo.ttad;

import android.content.Context;

import com.bytedance.sdk.openadsdk.TTAdConfig;
import com.bytedance.sdk.openadsdk.TTAdConstant;
import com.bytedance.sdk.openadsdk.TTAdManager;
import com.bytedance.sdk.openadsdk.TTAdSdk;

public class TTAdManagerHolder {
    private static boolean isInit;

    public static TTAdManager get() {
        if (!isInit) {
            throw new RuntimeException("TTAdSdk is not init, please check.");
        }
        return TTAdSdk.getAdManager();
    }

    public static void init(Context context) {
        doInit(context);
    }

    //step1:接入网盟广告sdk的初始化操作，详情见接入文档和穿山甲平台说明
    private static void doInit(Context context) {
        if (!isInit) {
            TTAdSdk.init(context, buildConfig(context));
            isInit = true;
        }
    }

    private static TTAdConfig buildConfig(Context context) {
        return new TTAdConfig.Builder()
                .appId("5010122")
                .appName("快爽小说")
                .titleBarTheme(TTAdConstant.TITLE_BAR_THEME_DARK)
                //.allowShowNotify(true) //是否允许sdk展示通知栏提示，默认为true
                .debug(true) //测试阶段打开，可以通过日志排查问题
                .directDownloadNetworkType(TTAdConstant.NETWORK_STATE_WIFI, TTAdConstant.NETWORK_STATE_4G) //允许直接下载的网络状态集合
                .build();
    }
}
